<template>
  <!--基本信息  -->
  <div >
    <FormPanel
      ref="formPanel"
      :list="initForm"
      :cols="2"
      :formType="value.type"
      :labelWidth="110"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { selectOneByProgramId } from '@/api/cms-api/projectOperating/program/distribution';
import { getInfoBase } from '@/api/cms-api/projectOperating/program/push';

export default {
  mixins: [dictionary],
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      formValue: {}
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    //修改时，初始化页面数据
    async init() {
      var id = this.value.rowData['projectProgramId'];//营销方案ID
      var projectProgramOrgId = this.value.rowData['projectProgramOrgId'];//营销方案事业部关系表ID
      let param;
      //param = Object.assign({}, param, { projectProgramId: id });
      //param = Object.assign({}, param, { orgId: orgId });
      param = Object.assign({},param,{projectProgramOrgId:projectProgramOrgId,projectProgramId:id});
      //根据方案ID和事业部ID查询事业部方案下发状态、描述等信息
      const re = await selectOneByProgramId(param);
      //项目周期
      var twoDate = [];
      if(re.data.projectStartDate!=null && re.data.projectEndDate!=null){
        twoDate.push(re.data.projectStartDate);
        twoDate.push(re.data.projectEndDate);
      }

      let programStatus = re.data['programStatus'];
      let isFeiChu = false;
      if(programStatus==25281003){//已废除
        isFeiChu = true;
        //2019-11-22 废除附件控制不能下载，修改fail属性
        this.initForm.find(item => item.fieldName === 'fileUrl').fail = true;
      }
      this.initForm.forEach(x => {
        if (x.fieldName == 'hdzq') {
          x.initialValue = twoDate;
        } else if(x.fieldName == 'fileUrl'){//处理附件，如果已废除状态，只显示不下载
            let fileList = re.data[x.fieldName];
            //2019-11-22 废除附件控制不能下载，目前不需要置空url
            //if(isFeiChu){//已废除 
              // if(fileList!=null && typeof(fileList)!='undefined'){
              //   fileList.map(file => {
              //     file.url = null;
              //     return file;
              //   });
              // }
            //}
            x.initialValue = fileList;
        } else {
          x.initialValue = re.data[x.fieldName];
        }
      });
    },
    //搜索数据
    initFormFun() {
      return [
        {
          type: 'INPUT',
          label: '方案编号',
          fieldName: 'programCode',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '方案状态',
          fieldName: 'programStatus',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('2528'),
          disabled: true
        },
        {
          type: 'SELECT',
          label: '方案下发渠道',
          fieldName: 'programIssuedChannel',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('2530'),
          disabled: true
        },
        {
          type: 'RANGE_DATE',
          label: '项目周期',
          fieldName: 'hdzq',
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          initialValue: [],
          placeholder: '',
          style: { width: '100%' }
        },
        {
          type: 'INPUT',
          label: '事业部',
          fieldName: 'orgName',
          placeholder: '',
          initialValue: '',
          disabled: true,
          selfCols:2
        },

        {
          type: 'TEXT_AREA',
          label: '方案名称',
          fieldName: 'programName',
          rows: 2,
          selfCols:2,
          initialValue: '',
          placeholder: ''
           },
        {
          type: 'TEXT_AREA',
          label: '方案描述',
          fieldName: 'programDesc',
          rows: 2,
          selfCols:2,
          initialValue: '',
          placeholder: '',
         },
        {
          type: 'TEXT_AREA',
          label: '事业部描述',
          fieldName: 'distributionDesc',
          rows: 2,
          selfCols:2,
          initialValue: '',
          placeholder: ''
        },
        {
          type: 'SELECT',
          label: '是否二级审核',
          fieldName: 'isSecondaryAudit',
          placeholder: '',
          initialValue: '',
          // selfCols:1,
          itemList: this.createDictList('1004')
        },
        {
          type: 'UPLOAD_FILE',
          label: '附件',
          fieldName: 'fileUrl',
          selfCols:2,
          fail: false,//控制是否可以下载,true：不可下载
          upload: {
            actionUrl: '/api/file/oss/upload', //上传的地址
            fixedSize: [300, 500], //剪裁尺寸
            isCalcHeight: false,
            limit: 10 //上传数量
          },
          initialValue: '',
          disabled: false
        }
      ];
    },
    formChangeHandle(val) {
      val.programIssuedChannel = '25301002'; //事业部下发代码
      // debugger
      this.formValue = val;
      this.$emit('childByValue', true);
      this.$emit('formSave');
    }
  }
};
</script>
